<template>
  <div class="visitor-container">
    <div class="flex-row justify-between">
      <!-- search -->
      <div class="searchBox">
        <el-form inline :model="queryInfo" class="demo-form-inline" label-position="right" label-width="80px">
          <el-form-item label="车间编号">
            <el-input v-model="queryBase.numbering"  placeholder="请输入车间编号" />
          </el-form-item>
           <el-form-item label="车间名称">
            <el-input v-model="queryBase.name" placeholder="请输入车间名称" />
          </el-form-item>
          <el-form-item label="产线编号">
            <el-input v-model="queryInfo.productionLineNumber" placeholder="请输入产线编号" />
          </el-form-item>
          <el-form-item label="产线名称">
            <el-input v-model="queryInfo.productionLineName" placeholder="请输入产线名称" />
          </el-form-item>
          <el-form-item label="配置状态">
            <el-select v-model="queryInfo.configurationState" >
              <el-option
                v-for="item in statusList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="mg-top-4" style="flex-shrink: 0;">
        <el-button type="info" size="mini" @click="handleQuery">查询</el-button>
        <el-button size="mini" @click="reset">重置</el-button>
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="tableData" border
      header-cell-class-name="table-header-cell"
      header-row-class-name="table-header-row"
      class="table-container" >
      <el-table-column prop="workshopArchivesPo.numbering" label="车间编号" />
      <el-table-column prop="workshopArchivesPo.name" label="车间名称" />
      <el-table-column prop="productionLineNumber" label="产线编号" />
      <el-table-column prop="productionLineName" label="产线名称" />
      <el-table-column label="操作" align="center"  width="200" >
        <template slot-scope="scope">
           <!-- <el-link type="primary" :underline="false" class="upStr fz-1" @click="updateDetails(scope.row.workshopArchivesPo.id)"> -->
           <el-link type="primary" :underline="false" class="upStr fz-1" @click="updateDetails(scope.row)">
            配置
          </el-link>
          <span class="line">|</span>
          <el-link type="danger" :underline="false" @click=show(scope.row.id) class="upStr redBtn">
            预览
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      :total="total"
      :page-sizes="[2, 4, 6, 8]"
      :page-size="paging.pageSize"
      :current-page="currentPage"
      layout="total, prev, pager, next, jumper"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <!-- yulan -->
    <el-dialog title="产线预览" :visible.sync="dialogVisible" width="70%">
      <div class="show w-100P flex flex-column">
        <div class="show-top flex justify-between " style="min-height:150px;">
          <div class="show-top-l">
            <!-- 流程 -->
            <ul class="productionLinePre-ul w-100P flex">
              <li v-for="(item,index) in productionLineData" :key="index">
                <div class="circle-o">
                  <div :class="{'circle-i':true, active:item.state}"><span></span></div>
                </div>
                <span>{{item.name}}</span>
              </li>
            </ul>
          </div>
          <div class="show-top-r">
            <!-- <el-row v-for="(item,index) in productionLineData" :key="index">
              <el-col :span="8">{{item.name}}&nbsp;</el-col>
              <el-col :span="8">{{item.iotDeviceName}}&nbsp;</el-col>
              <el-col :span="8">{{item.id}}&nbsp;</el-col>
            </el-row> -->
            <el-table :data="productionLineData" style="width: 100%">
              <el-table-column prop="name" label="类型" />
              <el-table-column prop="iotDeviceName" label="设备名称" />
              <el-table-column prop="id" label="设备id" />
            </el-table>
          </div>
        </div>
        <div class="show-bot" style="min-height:150px;margin-bottom: 50px;">
          <el-row>
            <el-col :span="10" offset="1">
              <div class="show-bot-l">产线仪表</div>
              <!-- {{metertData}} -->
              <template>
                <el-table :data="metertData" style="width: 100%">
                  <el-table-column label="类型" >
                    <template slot-scope="scope">
                      <span>{{ scope.row.equipmentFunction | lineNames }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="equipmentName" label="设备名称" />
                  <el-table-column prop="code" label="设备编号" />
                  <!-- <el-table-column prop="state" label="状态" /> -->
                  <el-table-column label="状态" >
                    <template slot-scope="scope">
                      <span>{{ scope.row.state | lineStates }}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-col>
            <el-col :span="10" offset="1">
              <div class="show-bot-l">环境监测</div>
              <template>
                <el-table :data="environmentData" style="width: 100%">
                  <el-table-column label="类型" >
                    <template slot-scope="scope">
                      <span>{{ scope.row.equipmentFunction | lineNames }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column prop="equipmentName" label="设备名称" />
                  <el-table-column prop="code" label="设备编号" />
                  <!-- <el-table-column prop="state" label="状态" /> -->
                  <el-table-column label="状态" >
                    <template slot-scope="scope">
                      <span>{{ scope.row.state | lineStates }}</span>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10" offset="1">
              <div class="show-bot-l" style="martin-top:40px;">产线监控</div>
              <template>
                <el-table :data="equipmentPosData" style="width: 100%">
                  <!-- <el-table-column prop="equipmentFunction" label="类型" /> -->
                  <!-- <el-table-column label="类型" >
                    <template slot-scope="scope">
                      <span>{{ scope.row.equipmentFunction | lineNames }}</span>
                    </template>
                  </el-table-column> -->
                  <el-table-column prop="name" label="设备名称" />
                  <el-table-column prop="code" label="设备编号" />
                </el-table>
              </template>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { nameList, switchList } from '../equipmentmanage/consts'
import {
  findProductionProcessByLineId,
  findProductionLineMonitorByLineId,
  findProductionLinePageByParam,
  findWorkshopArchivesPageByParam,
  findEquipmentPageByParam,
} from '@/child-business/api/IndustrialVision' 
export default {
  name: 'Prolineset',
  data() {
    return {
      statusList: [
        {id: -1, name: '全部'},
        {id: 0, name: '未配置'},
        {id: 1, name: '已配置'}
      ],
      checkedids: [], // 已经选中的选项
      workshoplist: [],
      dialogtit: '新增',
      listLoading: true,
      currentPage: 1, // 默认当前页
      dialogVisible: false, // 提交
      paging: {
        pageNo: 1,
        pageSize: 12
      },
      queryBase: {
        numbering: '',
        name: ''
      },
      queryInfo: {
        productionLineName: '',
        configurationState:-1,
        productionLineNumber: ''
      },
      total: 0,
      tableData: [],
      productionLineData:[],
      metertData:[],
      environmentData:[],
      equipmentPosData:[],
      equipmentAllList:[], // 产品列表
    }
  },
  computed: {},
  filters: {
    lineNames(val){ // 产线名称
      const item = nameList.find(element => parseInt(element.id) === parseInt(val))
      const name = item ? item.name : ''
      return name
    },
    lineStates(val){ // 产线名称
      const item = switchList.find(element => parseInt(element.id) === parseInt(val))
      const name = item ? item.name : ''
      return name
    }
  },
  created() {
    this.getList()
    this.getworkshoplist()
    this.getfindEquipmentPageByParam()
  },
  methods: {
    //yulan
    show(id){
      this.dialogVisible = true
      this.productionLineData = []
      this.getfindProductionProcessByLineId(id)
    },
    //获取车间列表
    getworkshoplist() {
      findWorkshopArchivesPageByParam({ workshopArchivesVO: { name: '', numbering: ''}, pageNo: 1, pageSize: 10000}).then(response => {
        this.workshoplist = response.records
      })
    },
    // 获取产品列表
    getList() {
      this.listLoading = true
      findProductionLinePageByParam({ productionLineVo: this.queryInfo, ...this.paging, ...this.queryBase}).then(response => {
        this.total = response.total
        this.tableData = response.records
        this.paging.pageNo = response.pageNo
        this.paging.pageSize = response.pageSize
        this.listLoading = false
      })
    },
    handleSizeChange(val) {
      this.paging.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.paging.pageNo = val
      this.getList()
    },
    //重置
    reset() {
      this.paging.pageNo = 1
      this.queryInfo = {
        productionLineName: '',
        productionLineNumber: '',
        configurationState: -1
      }
      this.queryBase = {
        numbering: '',
        name: ''
      }
      this.getList()
    },
    // 查询
    handleQuery() {
      this.paging.pageNo = 1
      this.getList()
    },
    // 配置
    updateDetails(list){
      this.$router.push({ 
        path: '/IndustryBackstage/prolinesetpage',
        query: {
          id: list.id,
          numbering:list.workshopArchivesPo.numbering,
          name:list.workshopArchivesPo.name,
          configurationState: list.configurationState
        }
      })
    },
    // 产线预览
    getfindProductionProcessByLineId(id) {
      // 产线预览
      findProductionProcessByLineId({ lineId: id }).then(response => {
        this.productionLineData = response.productionProcess
      })
      // 产线仪表
      findProductionLineMonitorByLineId({ ProductionLineId: id }).then(response => {
        console.log('res',response)
        if(response.meter != null){
          this.metertData = response.meter
        }else {
          this.metertData = this.meterEmptyList
        }
        if(response.environment != null){
          this.environmentData = response.environment
        }else {
          this.environmentData = this.environmentEmptyList
        }
        //产线监控
        this.equipmentPosData = response.equipmentPos
      })
    },
    getfindEquipmentPageByParam() {
      findEquipmentPageByParam({equipmentVO: {},pageNo: 0,pageSize: 999}).then(response => {
        const linData = []
        response.records.forEach((item) => {
          linData.push({value:item.id,label:item.name})
        })
        this.equipmentAllList = linData
        // console.log(linData)
      })
    },
  }
}
</script>
<style lang="scss" scoped>
 @import '@/child-business/styles/IndustrialVision.scss';
 .el-checkbox{ 
   display: flex; justify-content: flex-start; width:33%;float:left; margin: vh(3px) 0; padding: 0 vw(7px);
  .el-checkbox__inner{margin-top:2px;}
 }
 .addForm{
  margin-left: 30px;
  .el-input{ width: 320px;}
  .el-select{ width: 320px;}
}
.show-top{
  .show-top-l{
    width: 35%;
    margin: 0 auto;
    max-height: 200px;
    overflow-y: auto;
  }
  .show-top-r{
    width: 45%;
    margin: 0 auto;
    .el-col{
      line-height: 1.5em
    };
  }
}
::v-deep .el-dialog__body{padding: 30px 20px 0}
// 产线预览环节图样式
.productionLinePre-ul{
  list-style: none;
  padding: 0;
  flex-wrap: wrap;
}
.productionLinePre-ul li{
  width: 19%;
  min-height: 80px;
  padding: vw(5px);
  text-align: center;
  position: relative;
}
.productionLinePre-ul li span{
  font-size: 12px;
  display: inline-block;
  max-width: 8em;
  overflow: hidden;
  word-wrap: break-word;
}

.circle-o{
  width: vw(48px);
  height: vw(48px);
  border-radius: 50%;
  border: vw(1px) solid #444;
  margin: 0 auto;
}
.circle-i{
  width: vw(28px);
  height: vw(28px);
  border-radius: 50%;
  border: vw(1px) solid #444;
  margin: 0 auto;
  margin-top: vw(9px);

}
.circle-i.active{
  border-color: #1890FF;
}
.circle-i::before{
  content: "";
  position: absolute;
  width: vw(20px);
  height: vw(1px);
  background: #444;
  display: inline-block;
  left: vw(-3px);
  top: vw(30px);
}
.circle-i::after{
  content: "";
  position: absolute;
  width: vw(20px);
  height: vw(1px);
  background: #444;
  display: inline-block;
  right: vw(-3px);
  top: vw(30px);
}
.productionLinePre-ul li:nth-child(1) .circle-i::before{
 background: transparent;
}
.productionLinePre-ul li:nth-last-child(1) .circle-i::after{
 background: transparent;
}
.show-bot-l {
  margin: 20px 0 10px;
}
</style>
